package com.xms.consumers.queryview;

import com.xms.queryview.event.CreateDefaultViewEvent;
import com.xms.queryview.service.IQueryViewCreaterService;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 事件消费者之创建默认视图
 * </p>
 *
 * @author migo
 * @since 2021/9/29
 */
@Service
public class CreateDefaultViewConsumer {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    private IQueryViewCreaterService _queryViewCreaterService;

    @Autowired
    public CreateDefaultViewConsumer(IQueryViewCreaterService queryViewCreaterService) {
        _queryViewCreaterService = queryViewCreaterService;
    }

    @SneakyThrows
    @Async
    @EventListener
    public void onApplicationEvent(CreateDefaultViewEvent event) {
        logger.info("CreateDefaultViewConsumer");
        _queryViewCreaterService.createDefaultView(event.source, event.attributes);
    }
}
